package com.atcumt.bytedance;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 输入：
 * 2
 * 1 1
 * 0 1
 * 输出最短路径对应坐标
 */
public class Main01 {

    static List<List<Integer>> res = new ArrayList<>();
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[][] nums = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                nums[i][j] = scan.nextInt();
            }
        }

        List<Integer> step = new ArrayList<>();
        dfs(nums, 0, 0, n, n, step);

        int len = Integer.MAX_VALUE;
        int idx = 0;

        for (int i = 0; i < res.size(); i++) {
            if (res.get(i).size() < len) {
                len = res.get(i).size();
                idx = i; // 筛选最短路径
            }
        }
        step = res.get(idx);
        for (int i = 0; i < step.size(); i+=2) {
            System.out.print("(" + step.get(i) + "," + step.get(i + 1) + ") ");
        }
        scan.close();
    }

    private static void dfs(int[][] nums, int i, int j, int n, int m, List<Integer> step) {
        // 越界
        if (i < 0 || i >= n || j < 0 || j >= m || nums[i][j] == 0) {
            return;
        }
        if (i == n - 1 && j == m - 1) {
            step.add(i);
            step.add(j);
            res.add(new ArrayList<>(step));

            step.remove(step.size() - 1);
            step.remove(step.size() - 1);
        } else {
            step.add(i);
            step.add(j);
            nums[i][j] = 0;
            dfs(nums, i + 1, j, n, m, step);
            dfs(nums, i, j + 1, n, m, step);
            dfs(nums, i - 1, j, n, m, step);
            dfs(nums, i, j - 1, n, m, step);
            nums[i][j] = 1;
            step.remove(step.size() - 1);
            step.remove(step.size() - 1);
        }
    }
}
